package com.xhwl.centiotdata.handler.alarm.impl;

import com.alibaba.fastjson.JSONObject;
import com.xhwl.centiotdata.handler.alarm.AlarmFactory;
import com.xhwl.centiotdata.handler.alarm.AlarmHandler;
import com.xhwl.common.constant.cent.alarm.AlarmConstant;
import com.xhwl.common.dto.cent.alarm.iot.IotAlarmBody;
import com.xhwl.common.dto.cent.alarm.iot.SingleSpeedDraughtFan;
import com.xhwl.common.dto.cent.device.DeviceDTO;
import com.xhwl.common.pojo.cent.alarm.AlarmManagement;
import org.springframework.stereotype.Component;

import java.time.ZoneId;
import java.util.Date;
import java.util.Objects;

/**
 * @Author Leon
 * @Description: TODO
 * @Date: 2022/4/19 14:36
 */
@Component
public class AlarmHuaWeiIotDASingleSpeedDraughtFanHandler extends AlarmHandler {
    @Override
    public void afterPropertiesSet() throws Exception {
        AlarmFactory.register("SingleSpeedDraughtFan", this);
    }

    @Override
    public void pushHuaWeiIotDAIotAlarmBody(IotAlarmBody t, DeviceDTO device) {
        SingleSpeedDraughtFan singleSpeedDraughtFan = JSONObject.parseObject(JSONObject.toJSONString(t.getProperties()), SingleSpeedDraughtFan.class);
        AlarmManagement alarmManagement = new AlarmManagement();
        alarmManagement.setAlarmTime(Date.from(t.getEvent_time().atZone(ZoneId.systemDefault()).toInstant()));
        alarmManagement.setDeviceId(device.getId());
        alarmManagement.setProjectId(device.getProjectId());
        if (Objects.equals(singleSpeedDraughtFan.getGZ1(), Boolean.FALSE)) {
            alarmManagement.setAlarmInventoryCode("35604008");
            sendMq(AlarmConstant.JINMAO_TOPIC,alarmManagement);
        }

        if (Objects.equals(singleSpeedDraughtFan.getYX1(), Boolean.FALSE)) {
            alarmManagement.setAlarmInventoryCode("33133942");
            sendMq(AlarmConstant.JINMAO_TOPIC,alarmManagement);
        }
    }
}
